package com.example.webcrawler.model;

import java.util.HashMap;
import java.util.Map;

public class ApiRequest {
    private String id;
    private String method;
    private String url;
    private String source;
    private Map<String, String> requestHeaders;
    private String requestBody;
    private Map<String, String> responseHeaders;
    private String responseBody;
    private Integer status;
    private String type;
    private boolean intercepted;
    private boolean modified;
    private long timestamp;
    private String flowId;

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    private Long responseTime;
    private String requestId;

    public String getRequestId() {
        return requestId;
    }

    // 默认构造函数
    public ApiRequest() {
        this.id = java.util.UUID.randomUUID().toString();
        this.requestHeaders = new HashMap<>();
        this.responseHeaders = new HashMap<>();
    }

    // 带参数的构造函数
    public ApiRequest(String method, String url, String source, Map<String, String> headers, String type) {
        this();
        this.method = method;
        this.url = url;
        this.source = source;
        this.requestHeaders = headers;
        this.type = type;
    }

    // getter和setter方法
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public Map<String, String> getRequestHeaders() {
        return requestHeaders;
    }

    public void setRequestHeaders(Map<String, String> requestHeaders) {
        this.requestHeaders = requestHeaders;
    }

    public String getRequestBody() {
        return requestBody;
    }

    public void setRequestBody(String requestBody) {
        this.requestBody = requestBody;
    }

    public Map<String, String> getResponseHeaders() {
        return responseHeaders;
    }

    public void setResponseHeaders(Map<String, String> responseHeaders) {
        this.responseHeaders = responseHeaders;
    }

    public String getResponseBody() {
        return responseBody;
    }

    public void setResponseBody(String responseBody) {
        this.responseBody = responseBody;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isIntercepted() {
        return intercepted;
    }

    public void setIntercepted(boolean intercepted) {
        this.intercepted = intercepted;
    }

    public boolean isModified() {
        return modified;
    }

    public void setModified(boolean modified) {
        this.modified = modified;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getFlowId() {
        return flowId;
    }

    public void setFlowId(String flowId) {
        this.flowId = flowId;
    }

    public Long getResponseTime() {
        return responseTime;
    }

    public void setResponseTime(Long responseTime) {
        this.responseTime = responseTime;
    }

    // 添加请求头
    public void addHeader(String name, String value) {
        if (this.requestHeaders == null) {
            this.requestHeaders = new HashMap<>();
        }
        this.requestHeaders.put(name, value);
    }

    // 添加响应头
    public void addResponseHeader(String name, String value) {
        if (this.responseHeaders == null) {
            this.responseHeaders = new HashMap<>();
        }
        this.responseHeaders.put(name, value);
    }

    @Override
    public String toString() {
        return "ApiRequest{" +
                "id='" + id + '\'' +
                ", method='" + method + '\'' +
                ", url='" + url + '\'' +
                ", source='" + source + '\'' +
                ", status=" + status +
                ", type='" + type + '\'' +
                '}';
    }


}
